﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Connection_gen
{
    public partial class Form1 : Form
    {
        Random gen = new Random((int)DateTime.Now.Ticks);


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.nUMBERSTableAdapter1.Fill(this.dataSetMain.NUMBERS);
            this.dIRECTIONSTableAdapter.Fill(this.dataSetMain.DIRECTIONS);
            this.cLIENTSTableAdapter.Fill(this.dataSetMain.CLIENTS);
            //this.cONNECTIONSTableAdapter1.Fill(this.dataSetMain.CONNECTIONS);

            for (int i = 0; i < Int32.Parse(maskedTextBox1.Text); i++)
            {
                int num = gen.Next(0, dataSetMain.NUMBERS.Rows.Count - 1);
                int target_num = gen.Next(100000, 999999);
                int duration = gen.Next(0, 60);
                int prefix = gen.Next(0, dataSetMain.DIRECTIONS.Rows.Count - 1);
                
                cONNECTIONSBindingSource.AddNew();
                
                DataRowView drv = (DataRowView)cONNECTIONSBindingSource.Current;
                drv["CONNECTION_ID"] = 0;
                drv["NUMBER_ID"] = dataSetMain.NUMBERS.Rows[num]["NUMBER_ID"];
                drv["TARGET_NUMBER"] = target_num;
                drv["CONNECTION_DATE"] = DateTime.Today.ToString();// "2/2/2002";//';//, 'DD/MM/YYYY');
                drv["DURATION"] = duration;
                drv["TARGET_PREFIX"] = dataSetMain.DIRECTIONS.Rows[prefix]["PREFIX"];
                drv["COST"] = 0;

                drv.EndEdit();
                cONNECTIONSBindingSource.EndEdit();
            }
            cONNECTIONSTableAdapter1.Update(dataSetMain.CONNECTIONS);
        }

   
        private void Form1_Load(object sender, EventArgs e)
        {
            //this.nUMBERSTableAdapter1.Fill(this.dataSetMain.NUMBERS);
            //this.dIRECTIONSTableAdapter.Fill(this.dataSetMain.DIRECTIONS);
            //this.cLIENTSTableAdapter.Fill(this.dataSetMain.CLIENTS);
            //this.cONNECTIONSTableAdapter1.Fill(this.dataSetMain.CONNECTIONS);
        }
    }


    //class RandomGenerator
    //{

    //    private Random gen;

    //    private int num = 0;

    //    private int[] cache;



    //    public RandomGenerator(int Num)
    //    {

    //        this.gen = new Random((int)DateTime.Now.Ticks);
    //        this.num = Num;
    //        this.cache = new int[Num];
    //    }

    //    public int[] Get(int left, int right)
    //    {
    //        for (int i = 0; i < this.num; i++)
    //        {
    //            this.cache[i] = this.gen.Next(left, right);
    //        }
    //        return this.cache;
    //    }
    //}
}
